What?
Why?
ggplot2 takes a different approach to graphics than other plotting packages in Rtidyverse is a collection of some R packagesggplot2 separatelydiamonds dataset from ggplot2Some of the terminologies used in ggplot2:
data- what we want to visualize and consists of variablesGeoms - geometric objects that are drawn to represent the data, such as bars, lines, and pointsaesthetics - visual properties of geoms, such as x and y position, line color, point shapes, etcmappings from data values to aestheticsTask - You want to plot a boxplot of cut and depth
Task - You want to plot a boxplot of cut and depth
Task - You want to plot a boxplot of cut and depth
Task - You want to plot a boxplot of cut and depth
ggplot2 can beAuto dataset from ISLR2 packageTask - You want to plot a scatterplot of mpg and displacement
Task - You want to plot the mean number of carat by cut from diamonds dataset
p3 <- diamonds |>
group_by(cut) |>
summarise(mean_carat = mean(carat)) |>
ggplot(aes(x = reorder(cut, mean_carat), y = mean_carat))+
geom_col(width = 0.70, fill = "#9ac5db")+
labs(title = "'Fair' Cut Has the Highest Mean Carat Value",
subtitle = "Mean Carat Value by Quality of the Cut",
y = "Mean Carat",
x = "Quality of the Cut",
caption = "Data Source : diamonds | Analysis by Particpant")
p3p4 <- diamonds |>
group_by(cut) |>
summarise(mean_carat = mean(carat)) |>
ggplot(aes(x = reorder(cut, mean_carat), y = mean_carat))+
geom_col(width = 0.70, fill = "#9ac5db")+
labs(title = "'Fair' Cut Has the Highest Mean Carat Value",
subtitle = "Mean Carat Value by Quality of the Cut",
y = "Mean Carat",
x = "Quality of the Cut",
caption = "Data Source : diamonds | Analysis by Particpant")+
coord_flip()+
theme_minimal()
p4txhousing data from ggplot2patchwork